<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        #app{
            padding: 5vw;
        }
        .top{
            display: flex;
            justify-content: space-between;
        }
        .top input{
            width: 75vw;
            height: 8vw;
            outline: none;
            border: none;
            background: grey;
        }
        .top span{
            color: aqua;
            line-height: 8vw;
        }
        .mid{
            display: flex;
            
        }
        .mid span{
            margin: 2vw 4vw 4vw 0;
            background: aqua;
            padding: 2vw 5vw;
            border-radius: 2vw;
            font-size: 3.5vw;
            color: white;
        }
        .mid span:last-child{
            margin-left: 0;
            background: red;
        }
        .end div{
            background: red;
            height: 8vw;
            color: white;
            margin: 3vw 0;
            line-height: 8vw;
            padding: 0 2vw;
        }
        .end div span:nth-child(2){
            margin: 0 2vw;
        }
        .end div span:last-child{
            float: right;
        }
        .colorful{
            background-color: aqua !important;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="top">
            <input type="text" v-model="innerText" placeholder="输入任务名称">
            <span @click="add()">新增</span>
        </div>
        <div class="mid">
            <span>全部任务({{list.length}})</span>
            <span>已完成({{list.length-unhas}})</span>
            <span>未完成({{unhas}})</span>
        </div>
        <h4>任务列表</h4>
        <div class="end">
            <div v-for="(item,index) in list" :key="index" :class="{colorful:item.status}">
                <input type="checkbox" :checked="item.status" @click="change(item)">
                <span>{{item.id}}</span>
                <span>{{item.think}}</span>
                <span @click="del(item)">删除</span>
            </div>
        </div>
        <div v-show="list.length==0" class="empty">任务列表为空，请添加一个新任务!</div>


    </div>
</body>
</html>
<script src="../vue-2.5.21.js"></script>
<script>
    var vm = new Vue({
        el:'#app',
        data:{
            innerText:'',
            list:[
                {id:'1',think:'今天',status:false}
            ]
        },
        methods:{
            add(){
                var obj = {id:this.list.length+1 , think:this.innerText , status:false}
                this.list.push(obj)
            },
            change(item){
                item.status = !item.status;
            },
            del(item){ 
                this.list.splice(item.id-1,1)
            }
        },
        computed:{
            unhas(){
                let arr =this.list.filter(item => {
                    return item.status ==false
                });
                return arr.length
            }
        }
    })
</script>